<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="Week Time Logs"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:outputScript name="js/jsfunctions.js" />
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form>
                <p:calendar value="#{timeLogController.weekDay}" id="weekDay" showOn="button" />
                <h:commandButton action="#{timeLogController.displayWeekTimeLog}" type="submit" value="View"/>
            </h:form>
            <h:form styleClass="jsfcrud_list_form" id="form">
                <h:outputText escape="false" value="#{bundle.ListTimeLogEmpty}" rendered="#{timeLogController.nestedItems.rowCount == 0}"/>
                <h:panelGroup rendered="#{timeLogController.nestedItems.rowCount > 0}">
                    <h:outputText value="#{timeLogController.nestedPagination.pageFirstItem + 1}..#{timeLogController.nestedPagination.pageLastItem + 1}/#{timeLogController.nestedPagination.itemsCount}"/>&nbsp;
                    <h:commandLink action="#{timeLogController.previous}" value="#{bundle.Previous} #{timeLogController.nestedPagination.pageSize}" rendered="#{timeLogController.nestedPagination.hasPreviousPage}"/>&nbsp;
                    <h:commandLink action="#{timeLogController.next}" value="#{bundle.Next} #{timeLogController.nestedPagination.pageSize}" rendered="#{timeLogController.nestedPagination.hasNextPage}"/>&nbsp;
                    <h:dataTable id="mytable" value="#{timeLogController.nestedItems}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Day"/>
                            </f:facet>
                            <h:outputText value="#{item.day}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Date"/>
                            </f:facet>
                            <h:outputText value="#{item.date}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Details"/>
                            </f:facet>
                                <h:panelGroup rendered="#{item.timlog.size()> 0}">
                                    <h:dataTable value="#{item.timlog}" var="tl">
                                        <h:column>
                                            <f:facet name="header">
                                                <h:selectBooleanCheckbox onchange='SelectAllCheckboxesSpecific(this)'/>
                                            </f:facet>
                                            <h:selectBooleanCheckbox value="#{timeLogController.checked[tl.tlId]}" />
                                        </h:column>

                                        <h:column>
                                            <f:facet name="header">
                                                <h:outputText value="#{bundle.ListTimeLogTitle_project}"/>
                                            </f:facet>
                                            <h:outputText value="#{tl.project.projectName}"/>
                                        </h:column>

                                        <h:column>
                                            <f:facet name="header">
                                                <h:outputText value="#{bundle.ListTimeLogTitle_task}"/>
                                            </f:facet>
                                            <h:outputText value="#{tl.task}"/>
                                        </h:column>

                                        <h:column>
                                            <f:facet name="header">
                                                <h:outputText value="#{bundle.ListTimeLogTitle_activity}"/>
                                            </f:facet>
                                            <h:outputText value="#{tl.activity}"/>
                                        </h:column>

                                        <h:column>
                                            <f:facet name="header">
                                                <h:outputText value="#{bundle.ListTimeLogTitle_workedHours}"/>
                                            </f:facet>
                                            <h:outputText value="#{tl.workedHours}"/>
                                            <h:panelGroup rendered="#{tl.workedHours-8 >0}">
                                                <h:outputText value="  overtime   #{tl.workedHours-8}"/>
                                            </h:panelGroup>
                                        </h:column>

                                        <h:column>
                                            <f:facet name="header">
                                                <h:outputText value="#{bundle.ListTimeLogTitle_date}"/>
                                            </f:facet>
                                            <h:outputText value="#{tl.date}">
                                                <f:convertDateTime pattern="MM/dd/yyyy" />
                                            </h:outputText>
                                        </h:column>

                                        <h:column>
                                            <f:facet name="header">
                                                <h:outputText value="#{bundle.ListTimeLogTitle_status}"/>
                                            </f:facet>
                                            <h:outputText value="#{tl.status}"/>
                                        </h:column>

                                        <h:column>
                                            <f:facet name="header">
                                                <h:outputText value="&nbsp;"/>
                                            </f:facet>
                                            <h:commandLink action="#{timeLogController.prepareView(tl.tlId)}" value="#{bundle.ListTimeLogViewLink}"/>
                                            <h:outputText value=" "/>
                                            <h:commandLink rendered="#{tl.status != 'submitted'}" action="#{timeLogController.prepareEdit(tl.tlId)}" value="#{bundle.ListTimeLogEditLink}"/>
                                        </h:column>
                                    </h:dataTable>
                                </h:panelGroup>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Day Worked Hours"/>
                            </f:facet>
                            <h:outputText value="#{item.dayHours}"/>
                        </h:column>
                    </h:dataTable>
                    <h:outputLabel title="#{bundle.Total_Worked_Days}" value="#{bundle.Total_Worked_Days}"/>
                    <h:outputText value="${totalWorkedDays}" title="#{bundle.Total_Worked_Days}"/><br />

                    <h:outputLabel title="#{bundle.weekDays_Hour}" value="#{bundle.weekDays_Hour}"/>
                    <h:outputText value="${weekDaysHours-overTimeHours}" title="#{bundle.weekDays_Hour}"/><br />

                    <h:outputLabel title="#{bundle.overTimes_Hour}" value="#{bundle.overTimes_Hour}"/>
                    <h:outputText value="${overTimeHours}" title="#{bundle.overTimes_Hour}"/><br />

                    <h:outputLabel title="#{bundle.totalhours}" value="#{bundle.totalhours}"/>
                    <h:outputText value="${weekDaysHours}" title="#{bundle.totalhours}"/>
                </h:panelGroup>
                <br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <h:commandButton action="#{timeLogController.prepareCreate}" type="submit" value="#{bundle.ListTimeLogCreateLink}"/>
                <h:commandButton rendered="${totalWorkedDays>0}" value="Delete" action="#{timeLogController.deleteSelectedNested}" />
                <h:commandButton rendered="${totalWorkedDays>0}" value="Submit" action="#{timeLogController.submitNested}" />
                <h:button rendered="${type=='admin'}" value="Back to Home" outcome="/index" />
                <h:button rendered="${type=='user'}" value="Back to Home" outcome="/userhome"/>
            </h:form>
        </ui:define>
    </ui:composition>
</html>